//党支部321提醒的数据
import API from "@/api/api-chat-list";

export const thePartyBranch321 = {
  // 命名空间的作用：为了让当前vuex模块里面的状态名和函数名和其他空间的命名不产生冲突
  namespaced: true,
  state: {
    workListRoles: ['provinceWork','cityWork','branchWork'],//321提醒表角色
    thePartyBranchRemind:false,//321提醒按钮状态
    roleIds:[],//用户权限信息
    hasWorkReminderRole:false,//登录用户是否有任意一个角色.
    orgList: {}, //公司列表
    userInfo: {}, //用户信息
    selectCompany: false, // 是否允许选择公司名称
    selectBranch: false, // 是否允许选择支部名称
    theBranchHasBeenCompleted:null,//支部已完成
    branchUnfinished:null,//支部未完成
    SaveTheCompanyIssued: {
      path: "/SaveTheCompanyIssued",
      name: "SaveTheCompanyIssued",
      title: "省公司下发",
    }, //省公司下发路由
    DirectlyUnderThePartyCommitteeIssued: {
      path: "/DirectlyUnderThePartyCommitteeIssued",
      name: "DirectlyUnderThePartyCommitteeIssued",
      title: "直属党委下发",
    }, //直属党委下发
    CityWorkList: {
      path: "/CityWorkList",
      name: "CityWorkList",
      title: "市公司下发",
    }, //市公司下发
    BranchTask: {
      path: "/BranchTask",
      name: "BranchTask",
      title: "支部任务",
    }, //支部任务
    ziLuBy: [], //子路由
  },
  mutations: {
    //公司列表
    setOrgList(state, value) {
      state.orgList = value;
    },
    //用户信息
    setUserInfo(state, value) {
      state.userInfo = value;
    },
    //用户权限
    setRoles(state, value) {
      state.roleIds = value;//用户权限
      const roleIdsSet = new Set(state.roleIds);
      state.hasWorkReminderRole = state.workListRoles.some(item => roleIdsSet.has(item));
      state.ziLuBy = [];//子路由
      if (value.includes("provinceWork")) {
        // 如果是provinceWork，就显示所有界面，和查询条件下拉框
        state.ziLuBy.push(
            state.SaveTheCompanyIssued,
            state.DirectlyUnderThePartyCommitteeIssued,
            state.CityWorkList,
            state.BranchTask
        );
        state.selectCompany = true;
        state.selectBranch = true;
      } else if (value.includes("cityWork")) {
        // 如果是cityWork，就判断用户是否是省公司，是就显示直属党委下发界面，否则，显示市公司下发界面
        if (state.userInfo.companyName === "省公司") {
          state.ziLuBy.push(state.DirectlyUnderThePartyCommitteeIssued);
          // 允许公司名称和支部名称选择
          state.selectCompany = true;
        } else {
          state.ziLuBy.push(state.CityWorkList);
        }
        // 允许支部名称选择
        state.selectBranch = true;
        // 显示支部下发界面
        state.ziLuBy.push(state.BranchTask);
      } else {
        // 如果是branchWork，则只显示支部下发界面
        state.ziLuBy.push(state.BranchTask);
      }
      state.thePartyBranchRemind = true;//321提醒按钮权限打开
    },
    setTheBranchOfTaskData(state,value){
      state.theBranchHasBeenCompleted = value.filter(
          (item) => item.finishStatus === "已完成"
      );
      state.branchUnfinished = value.filter(
          (item) => item.finishStatus === "未完成"
      );
    }
  },
  actions: {
    //用户信息
    async getUserInfo(context) {
      const userInfoRes = await API.getUserInfo({});
      context.commit("setUserInfo", userInfoRes.data);
    },
    //公司列表
    async getOrg(context) {
      const res = await API.getOrgTree();
      context.commit("setOrgList", res.data);
    },
    //用户权限
    async getRoles(context) {
      const rolesData = await API.getRoles();
      context.commit("setRoles", rolesData.data);
    },
    //支部任务
    async getTheBranchOfTaskData(context,{companyName,orgUuid}){
      //支部任务任务列表
      const param = {
        page:'',
        pageSize:'',
        companyName:companyName,
        orgUuid:orgUuid,
        startTime:'',
        endTime:'',
      };
      const data = await API.queryBranchWorkList( param );
      context.commit("setTheBranchOfTaskData", data.data);
    }
  },
};



